<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
	<title><spring:message code="message.lable.ShouHuoDetail"/></title>
	<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1><spring:message code="message.lable.ShouHuoDetail"/></h1>
        <ol class="breadcrumb">
        	<li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
        	<li class="active"><a href="#"><spring:message code="message.list.ShangPinCaiGou"/></a></li>
            <li><a href="#"><spring:message code="message.list.ShouHuoRuKu"/></a></li>
            <li><a href="#"><spring:message code="message.list.ShouHuoQuqRen"/></a></li>
        </ol>
    </section>
    
 <section class="content">
        <div class="box box-success">
            <div class="box-body">
                <div class="input">
				<div class="textalign1"><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao"/></div>
	                    <div class="boxinput">
	                    <input type="text" class="textinput" id="drugName"	name="drugName" placeholder="<spring:message code="message.listForm.tongYongMing"/>" />
	                    </div>
                	<div class="textalign1"><spring:message code="message.listForm.yaoPinBianMa"/><spring:message code="message.yanZheng.maoHao"/></div>
	                    <div class="boxinput">
	                    <input type="text" class="textinput" id="drugCode"	name="drugCode" placeholder="<spring:message code="message.listForm.yaoPinBianMa"/>" />
	                    </div>
				<div class="textalign1"><spring:message code="message.listForm.shengChanQiYe"/><spring:message code="message.yanZheng.maoHao"/></div>
	                    <div class="boxinput">
	                    <input type="text" class="textinput" id="compName"	name="compName" placeholder="<spring:message code="message.listForm.shengChanQiYe"/>" />
	                    </div>
                
					<div class="textalign1" >
					<button type="button" onclick="gridSerch();" class="btn btn-success btn-sm" id="selectDicCompType"><spring:message code="message.button.seachSpacing"/></button>
                </div>
                </div>
            </div>
        </div>
		

        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
        	<button type="button" onclick="orderConfirmSelect();" class="btn btn-default btn-sm"><spring:message code="message.button.QueRenShouHuo"/></button>
        	<button type="button" onclick="notArrived();" class="btn btn-default btn-sm"><spring:message code="message.listForm.WeiDaoHuo"/></button>
            <button type="button" onclick="window.location.href='${ctx}/purOrderInfo/toConfirmRecp.html'" class="btn btn-default btn-sm"><spring:message code="message.button.getBackSpacing"/></button>
        </div>
        
         
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
  //绑定回车
    $('#drugName,#drugCode,#compName').bind('keydown', function(event) { 
        if (event.keyCode == "13") {
            $('#selectDicCompType').click();
        }
    });	
    $("#drugName").focus();//加载页面光标在第一个查询框内
    
    
        $(function () {
            
            $("#gridlist").jqGrid({
            	  url: "${ctx}/purOrderInfo/getConfirmRecpDetailDataList.html?orderPackId=${param.orderPackId}",
                  mtype: "POST",
                  datatype: "json",
                  autowidth: true,
                  shrinkToFit: false,
                  height: 310,
                colNames: [
                           'delDetailId',
                           'orderId',
                           'drugId',
                           '<spring:message code="message.listForm.DingDanMingXiBianHao"/>',
                           '批次号',
                           '<spring:message code="message.listForm.DingDanBaoHao"/>',
                           '<spring:message code="message.listForm.CaiGouJia"/>',
                           '<spring:message code="message.listForm.CaiGouXianJia"/>',
                           '<spring:message code="message.listForm.CaiGouShuLiang"/>',
                           '<spring:message code="message.listForm.CaiGouJinE"/>',
                           '<spring:message code="message.listForm.PeiSongShuLiang"/>',
				           '<spring:message code="message.listForm.PeiSongJinE"/>',
				           '<spring:message code="message.listForm.DaoHuoShuLiang"/>',
                           '<spring:message code="message.lable.DaoHuoZhuangTai"/>',
                           '<spring:message code="message.listForm.yaoPinBianMa"/>',
	                       '<spring:message code="message.listForm.tongYongMing"/>', 
	                       '<spring:message code="message.listForm.jiXing"/>',
	                       '<spring:message code="message.listForm.guiGe"/>',
	                       '<spring:message code="message.listForm.zhuanHuanXiShu"/>',
	                       '<spring:message code="message.listForm.baoZhuangDanWei"/>', 
	                       '<spring:message code="message.listForm.caiZhi"/>',
	                       '<spring:message code="message.listForm.shengChanQiYe"/>'
                           ],
                colModel: [
					{ name: 'delDetailId', index: 'ship', hidden:true, width: 80, align: "center", sortable:false },
					{ name: 'orderId', index: 'ship', hidden:true, width: 80, align: "center", sortable:false },
					{ name: 'drugId',index:'n1', width:80, hidden:true,align:"center", sortable:false  },
					{ name: 'orderCode', index: 'ship',  width: 210,hidden:true, align: "center", sortable:false },
					{ name: 'approveCode', index: 'ship',  width: 210, align: "center", sortable:false },
					{ name: 'orderPackId', index: 'ship',hidden:true, width: 150, align: "center", sortable:false },
					{ name: 'proPrice', index: 'ship', width: 60, align: "right" , sortable:false,
                 	   formatter:function(cellvalue, options, row){
                           return formatAmount(cellvalue, options, row);
                       }},
					{ name: 'proPriceLimit', index: 'ship', width: 60, align: "right" , sortable:false},
					{ name: 'proCount', index: 'ship', width: 80, align: "center" , sortable:false },
					{ name: 'buyPrice', index: 'sdate', width: 80, align: "right", sortable:false},
					{ name: 'delCount', index: 'ship', width: 80, align: "center", sortable:false },
					{ name: 'delPrice', index: 'sdate', width: 80, align: "right", sortable:false},
					{ name: 'recpCount', index: 'sdate', width: 80, align: "right", sortable:false},
                    { name: 'isRecepted', index: 'sdate', width: 80, align: "center", sortable:false},
					{ name: 'drugCode', index: 'sdate', width: 90, align: "center", sortable:false,
						formatter:function(cellvalue, options, row) {
							return "<a href=\"javascript:$.HN.dialog.opendialog('"+row.drugId+"','<spring:message code="message.lable.proddruginfoSTDdetail"/>','${ctx}/stdDrug/drugInfoDetail.html?drugId="+row.drugId+"','800px','400px',function operResult(val){return operResult;})\">"+cellvalue+"</a>"
                    	}},
					{ name: 'drugName', index: 'name', width: 100,align:"center", sortable:false },
                    { name: 'formName', index: 'stock', width: 60 , align: "center", sortable:false },
                    { name: 'specName', index: 'ship', width: 60, align: "center", sortable:false  },
                    { name: 'factor', index: 'ship', width: 60, align: "center", sortable:false },
                    { name: 'unit', index: 'ship', width: 70, align: "center", sortable:false },
                    { name: 'materialName', index: 'ship', width: 80, align: "center", sortable:false },
                    { name: 'compName', index: 'ship', width: 150, align: "center" ,  sortable:false,
						 formatter:function(cellvalue, options,row) {
							 return "<a href=\"javascript:$.HN.dialog.opendialog('"+row.delCompId+"','"+cellvalue+"','${ctx}/stdCompinfo/toStdCompinfoDetail.html?compId="+row.delCompId+"','800px','400px',function operResult(val){return operResult;})\">"+cellvalue+"</a>";
			     		} }
                ],
                rowNum: 20,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                 gridComplete: function(){
            		var ids = jQuery("#gridlist").jqGrid('getDataIDs');
            		for(var i=0;i < ids.length;i++){
            			var id = ids[i];
            			var rowdata = $("#gridlist").jqGrid('getRowData', id);
            			a = "<a href='${ctx}/purOrderInfo/toConfirmRecpDetail.html?orderPackId="+rowdata.orderPackId+"'><spring:message code="message.button.QueRenShouHuo"/></a>";
            			if (rowdata.isRecepted=='<spring:message code="message.list.DaiShouHuo"/>'){
            				c = "<input class=\"\" type=\"text\" id=\"recpCount"+id+"\" value=\""+rowdata.delCount+"\" />";
            			}
            			else if (rowdata.isRecepted=='<spring:message code="message.listForm.YiDaoHuo"/>'){
            				c = rowdata.recpCount;
            			}
            			else if (rowdata.isRecepted=='<spring:message code="message.listForm.WeiDaoHuo"/>'){
            				c = "<spring:message code="message.listForm.WeiDaoHuo"/>";
            			} else {
            				c = "";
            			}
            			
            			jQuery("#gridlist").jqGrid('setRowData',ids[i],{oper:a,recpCount:c });
            		}	
            	},  
                caption: "${param.orderPackId}/${delCompName}/${param.delMoney}",
                jsonReader: {
                    repeatitems: false,
                    id: "ids"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        
        
        
        
        //查询
        function gridSerch(){
        	var drugCode = $.trim($("#drugCode").val());
        	var drugName = $.trim($("#drugName").val());
        	var compName = $.trim($("#compName").val());
        	$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{
    	        	"drugCode":drugCode,
    	        	"drugName":drugName,
    	        	"compName":compName
    	        	},     		
    	        	page:1
        	    }).trigger("reloadGrid"); //重新载入  
        	}
        	
        
        
        //整包到货确认
        function allorderConfirmSelect(){
	       	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
	   		
	   		$.HN.message.confirm('确定加入所选吗？', '', '').on(function (e) {
	   			if (e) {
	   				var list = [];
	   	    		for (var i=0; i<rowIds.length; i++) {
	   	    			rowId = rowIds[i];
	   	    			var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
	   	    			list.push({"orderPackId":rowdata.orderPackId});
	   	    		}
	   			$.post("${ctx}/purOrderInfo/confirmByPack.html?orderPackId=${param.orderPackId}", {
	   	    			"array" : json.jsonToString(list)
	   	    		}, function(result) {
	   	    			if (result.success) {
	   	    				$.HN.message.alert("操作成功！", "<spring:message code="message.HN.alert.type"/>", "success");
	   	    				gridSerch();
	   	    				//document.location = "${ctx}/purOrderInfo/toConfirmRecpDetail.html?orderPackId=${param.orderPackId}&delCompName=${delCompName}";
	   	    			} else {
	   	    				$.HN.message.alert(result.msg , "<spring:message code="message.HN.alert.type"/>", "error");
	   	    			}
	   	    		}, "json")
	   			}
	   		}).trigger("reloadGrid"); //重新载入  ;
	       }
      //整包未到货
        function allnotArrived(){
	   		$.HN.message.confirm('确定加入所选吗？', '', '').on(function (e) {
	   			if (e) {
	   			
	   				
	   			$.post("${ctx}/purOrderInfo/noArrivedByPack.html", {
	   	    			"orderPackId" : "${param.orderPackId}"
	   	    		}, function(result) {
	   	    			if (result.success) {
	   	    				gridSerch();
	   	    				$.HN.message.alert("操作成功！", "<spring:message code="message.HN.alert.type"/>", "success");
	   	    				gridSerch();
	   	    				//document.location = "${ctx}/purOrderInfo/toConfirmRecpDetail.html?orderPackId=${param.orderPackId}&delCompName=${delCompName}";
	   	    			} else {
	   	    				$.HN.message.alert(result.msg , "<spring:message code="message.HN.alert.type"/>", "error");
	   	    			}
	   	    		}, "json")
	   			}
	   		}).trigger("reloadGrid"); //重新载入  ;
	       }
        
        
        
        //到货确认
         function orderConfirmSelect(){
        	 var reg = new RegExp(regexEnum.intege1);
        	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请选择要操作的行！", "<spring:message code="message.HN.alert.type"/>", "warn");
    			return;
    		}
    		
    		var list = [];
            for (var i=0; i<rowIds.length; i++) {
                rowId = rowIds[i];
                if ($.trim($("#recpCount"+rowId).val()).length < 1){
                    $.HN.message.alert("<spring:message code="message.yanZheng.QingTianXieDaoHuoShuLiang"/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code="message.HN.alert.type"/>", "warn");
                    return;
                }
                var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
                
                if ($.trim($("#recpCount"+rowId).val())>rowdata.delCount){
                    $.HN.message.alert("<spring:message code="message.yanZheng.DaoHuoShuNotDaYuPeiHuoShu"/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code="message.HN.alert.type"/>", "warn");
                    return;
                }
                if(!reg.test($.trim($("#recpCount"+rowId).val()))){
                    $.HN.message.alert("<spring:message code="message.yanZheng.DaoHuoShuLiangWeiZhengZhengShu"/><spring:message code="message.yanZheng.ganTanHao"/><spring:message code="message.yanZheng.qingChongXinShuRu"/>", "<spring:message code="message.HN.alert.type"/>", "warn");
                    return;
                }
                
            list.push({"delDetailId":rowdata.delDetailId,"approveCode":rowdata.approveCode,"orderCode":rowdata.orderCode,"recpCount":$.trim($("#recpCount"+rowId).val())});
            }
    		
    		$.HN.message.confirm('确定加入所选吗？', '', '').on(function (e) {
    			if (e) { 
    				$.post("${ctx}/purOrderInfo/confirmRecp.html", {
    	    			"array" : json.jsonToString(list)
    	    		}, function(result) {
    	    			//var result = eval("("+result+")");
    	    			if (result.success) {
    	    				gridSerch();
    	    				$.HN.message.alert("操作成功！", "<spring:message code="message.HN.alert.type"/>", "success");
    	    				gridSerch();
    	    				//document.location = "${ctx}/purOrderInfo/toConfirmRecpDetail.html?orderPackId=${param.orderPackId}&delCompName=${delCompName}";
    	    			} else {
    	    				$.HN.message.alert(result.msg , "<spring:message code="message.HN.alert.type"/>", "error");
    	    			}
    	    		}, "json")
    			}
    		});
        }
        
       //未到货
         function notArrived(){
        	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请选择要操作的行！", "<spring:message code="message.HN.alert.type"/>", "warn");
    			return;
    		}
    		$.HN.message.confirm('确定加入所选吗？', '', '').on(function (e) {
    			if (e) {
    			
    				var list = [];
    	    		for (var i=0; i<rowIds.length; i++) {
    	    			rowId = rowIds[i];
    	    			var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
    	    		list.push({"orderId":rowdata.orderCode});
    	    		}
    			$.post("${ctx}/purOrderInfo/notArrived.html", {
    	    			"array" : json.jsonToString(list)
    	    		}, function(result) {
    	    			//var result = eval("("+result+")");
    	    			if (result.success) {
    	    				gridSerch();
    	    				$.HN.message.alert("操作成功！", "<spring:message code="message.HN.alert.type"/>", "success");
    	    				gridSerch();
    	    				//window.location.href='${ctx}/purOrderInfo/toConfirmRecpDetail.html?orderPackId=${param.orderPackId}&delCompName=${delCompName}';
    	    				//document.location = "${ctx}/purOrderInfo/toConfirmRecpDetail.html";
    	    			} else {
    	    				$.HN.message.alert(result.msg , "<spring:message code="message.HN.alert.type"/>", "error");
    	    			}
    	    		}, "json")
    			}
    		});
        }
    </script>
</body>
</html>